package org.example.demo21.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 *
 * @author guocong
 * @since 2024/3/11 15:50
 */
@Configuration
public class CaffeineConfig {


    @Bean
    public Cache<String, Object> caffeineCache() {
        return Caffeine.newBuilder()
                // 设置10秒后过期,方便后续观察现象
                .expireAfterAccess(10, TimeUnit.SECONDS)
                // 初始容量为100
                .initialCapacity(1000)
                // 最大容量为200
                .maximumSize(5000)
                .build();
    }


}
